// pages/integralShop/integralShop.js
import profile from '../../profile.js'

const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    lang: app.globalData.language,
    index: profile.integralShop,

    shopNavList: profile.integralShop.shopNavList,
    navNum: 0,
  },

  // 立即兑换
  exchangeTap: function (e) {
    let id = e.currentTarget.id;
    if (id == "disabled") return;
    wx.navigateTo({
      url: '../../pages/integralShopForm/integralShopForm',
    })
  },

  // nav 切换
  navTap: function (e) {
    let id = e.currentTarget.id, list = this.data.shopNavList;
    for (let i=0;i<list.length;i++) {
      if (id == list[i].id) {
        list[i].onthis = true
      }else{
        list[i].onthis = false
      }
    }
    this.setData({
      shopNavList: list,
      navNum: id
    })
  },

  // 语言切换事件
  menuTap: function (e) {
    this.setData({
      lang: e.detail.lang
    })
    if (app.globalData.language == 'cn'){
      wx.setNavigationBarTitle({
        title: '积分兑换'
      })
    }else{
      wx.setNavigationBarTitle({
        title: 'integral shop'
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      lang: app.globalData.language
    })
    if (app.globalData.language == 'cn'){
      wx.setNavigationBarTitle({
        title: '积分兑换'
      })
    }else{
      wx.setNavigationBarTitle({
        title: 'integral shop'
      })
    }
  },
})